﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace SDFL.KeyPoints.DesignPattern.Singleton.Structural
{
     class Program
     {
         static void Main(string[] args)
         {
             // Test thread unsafe Singleton
             Thread[] trlist = new Thread[10];
             for (int i = 0; i < trlist.Length; i++)
             {
                trlist[i] = new Thread(delegate()
                {
                   ThreadUnsafeSingleton mt = ThreadUnsafeSingleton.Instance;
                });

                trlist[i].Start();
                Console.WriteLine("thread {0} started", i);
             }
             
             // Test thread safe Singleton
             Thread[] trlist2 = new Thread[10];

             for (int i = 0; i < trlist2.Length; i++)
             {
                 trlist2[i] = new Thread(delegate()
                 {
                     ThreadSafeSingleton mt = ThreadSafeSingleton.Instance;
                 });

                 trlist2[i].Start();
                 Console.WriteLine("thread {0} started", i);
             }

             // Test .NET threadsafe singleton
             
             Thread[] trlist3 = new Thread[10];

             for (int i = 0; i < trlist3.Length; i++)
             {
                 trlist3[i] = new Thread(delegate()
                 {
                     DotNETThreadSafeSingleton mt = DotNETThreadSafeSingleton.GetDotNETThreadSafeSingleton();
                 });

                 trlist3[i].Start();
                 Console.WriteLine("thread {0} started", i);
             }

             
             Console.Read();
         }

         

         
     }

}
